package com.game.system;

import com.game.actions.ShootAction;
import com.game.actions.TurboAction;
import com.game.objects.Environment;
import com.game.objects.Player;
import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;

public class FlightHandler extends InputHandler{
	private Player player;
	private Environment ev;
	private ShootAction shootAction;
	private boolean buttonReleased;
	public FlightHandler(Player player, Environment ev){
		this.player = player;
		this.ev = ev;
		setKeyBindings();
        setActions();
	}
	private void setKeyBindings() {
		KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();
		
		keyboard.set("turbo", KeyInput.KEY_SPACE);
	}
	private void setActions() {
		shootAction = new ShootAction(player, ev);
		TurboAction turbo = new TurboAction(player, ev);
		addAction(turbo, "turbo", false);
	}
	public void update(float time){
		super.update(time);
		if(MouseInput.get().isButtonDown(0) && buttonReleased){
			shootAction.performAction(event);
			buttonReleased=false;
		}
		if(!MouseInput.get().isButtonDown(0)){
			buttonReleased=true;
		}
		if(MouseInput.get().isButtonDown(1)){
			shootAction.performAction(event);
		}
	}
}